<?php
namespace app\base\controller;
/* *
 * 返回信息类
 * */
class ErrorController extends BaseController{

    //ajax返回信息
    protected function jsonMsg($msg,$status = 0,$url =NULL){
        $this->layout = NULL;
        echo json_encode(array("info" => $msg,"status" =>$status,"url" => $url));
        exit;
    } 

    //page返回信息
    protected function pageMsg($msg,$status = 0,$url =NULL){
        $this->layout = NULL;
        $this->msg = $msg;
        $this->status = $status;
        $this->url = $url;
        $this->display('app/base/view/error_message');
        exit();
    }

    //404错误信息
    public function pageError($msg = 'HTTP 404 Page Not Found'){   
        $this->layout = NULL;
        header('HTTP/1.1 404 Not Found'); 
        header("status: 404 Not Found");
        $this->msg = $msg;
        $this->status = 0;
        $this->display('app/base/view/error_message');
        exit();
    }

    //系统404输出
	public function error404($e=null){
		header('HTTP/1.1 404 Not Found'); 
		header("status: 404 Not Found");
		$this->error($e);
	}
	
	//系统错误输入
	public function error($e=null){
		if( false!==stripos(get_class($e), 'Exception')  ){
			$this->errorMessage = $e->getMessage();
			$this->errorCode = $e->getCode();
			$this->errorFile = $e->getFile();
			$this->errorLine = $e->getLine();
			$this->trace = $e->getTrace();		
		}
				
		//关闭调试或者是线上版本，不显示详细错误
		if( false==config('DEBUG') || 'production'==config('ENV') ){
			$tpl = 'error_production';
			//记录错误日志
			
		}else{
			$tpl = 'error_development';
		}
		$this->display('app/base/view/'.$tpl);
	}	

}